package com.tobby.camel.camelinaction.chapter3.transform;

import java.util.Arrays;
import java.util.List;

public class OrderToCsvBean {

	public static String map(String custom) {
		String id = custom.substring(0, 9);
		String customerId = custom.substring(10, 19);
		String date = custom.substring(20, 29);
		String items = custom.substring(30);
		String[] itemIds = items.split("@");

		StringBuilder csv = new StringBuilder();
		csv.append(id.trim());
		csv.append(",").append(date.trim());
		csv.append(",").append(customerId.trim());
		List<String> itemIdsList = Arrays.asList(itemIds);
		itemIdsList.forEach(o -> {
			csv.append(",").append(o);
		});
		return csv.toString();
	}

}
